package com.example.administrator.mybitmap;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //创建一个200*200的位图，每个象素4个字节
        //Bitmap bitmap = Bitmap.createBitmap(200,200,Bitmap.Config.ARGB_8888);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.aa)
                .copy(Bitmap.Config.ARGB_8888,true);
        //创建画布对象，在画布上调用绘制方法，就可以将图形绘制到bitmap上
        Canvas canvas = new Canvas(bitmap);
        //创建画笔
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        //绘制一条直线
        canvas.drawLine(2.3f,2.3f,150f,150f,paint);
        //绘制文本
        canvas.drawText("周敏敏",2.3f,20f,paint);

        //获取显示图片
        ImageView imageView =(ImageView) findViewById(R.id.id_iv_pic);
        //将bitmap显示在图片控件上
        imageView.setImageBitmap(bitmap);
    }
}
